<?php

namespace app\admin\controller;
use app\base\controller\Base;
use think\Request;
use think\Cache;
use think\Config;
use think\Session;


class Bank extends Base
{
    public  $model;

    public function __construct()
    {
   $this->model = model("UsersBank");
        parent::__construct();
    }

    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {//
        $where = [];
        if(isset($this->mobile)&&!empty($this->mobile)){
            $where['u.mobile']=['like','%'.$this->mobile.'%'];
        }
        //时间的处理
     $res = $this->model->bank_page($where);
     return   resJson(1,$this->ecLang("query"),$res['res'],$res['pageInfo']);
    }


    /**
     *  增加银行
     */
    public function save(){
        $users =  new \app\out\model\Users;
        $users->where(['id'=>$this->RealData['user_id']])->find();
        if(empty($users)){
            return   failJson($this->ecLang("queryfail"));
        }
        $bank_noCount = $this->model->where("bank_no",$this->RealData['bank_no'])->count();
        if($bank_noCount>0){
            return   failJson("你添加的银行卡已存在");
        }
            $data = $this->RealData;
            $data['user_id'] = $this->RealData['user_id'];
            $inser_id =  $this->model->save($data);
            if(!$inser_id){
                return   failJson($this->ecLang("failInsert"));
            }
            return sucessJson($this->ecLang("scuessInsert"));

    }


    /**
     *  修改银行
     */
    public function upbank(){

        $data = $this->RealData;
        $data['mobiles'] = $this->RealData['mobile'];

        unset($data['mobile'],$data['bank_id']);
        $bank_noCount = $this->model->where("bank_no",$this->RealData['bank_no'])->whereor("id",$this->RealData['bank_id'])->count();
        if($bank_noCount>1){
            return   failJson("你添加的银行卡已存在");
        }

        $res  =  $this->model->save($data,['id'=>$this->RealData['bank_id']]);
        if(!$res){
            return   failJson("更新银行卡失败");
        }
        return sucessJson("更新银行卡成功");


    }



}
